﻿using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace DevTeam
{
    public class User
    {
        public int InitialUserId { get; set; }

        int userId;
        public int UserId
        {
            get { return userId; }
            set { userId = value; }
        }

        int deptId;
        public int DepartmentId
        {
            get { return deptId; }
            set { deptId = value; }
        }

        string userName;
        public string UserName
        {
            get { return userName; }
            set { userName = value; }
        }

        string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        string email;
        public string Email
        {
            get { return email; }
            set { email = value; }
        }

        public string PasswordHash { get; set; }

        public void SetYetki(DataTable dtYetki)
        {
            yetki.Clear();

            foreach (DataRow dr in dtYetki.Rows)
                yetki.Add(dr["YetkiId"].ToInt());
        }

        public bool isAdmin
        {
            get { return Session.Admins.Contains(UserId); }
        }

        private List<int> yetki = new List<int>();
        public bool YetkiliMi(int YetkiId)
        {
            if (isAdmin || yetki.Contains(YetkiId))
                return true;
            else
                return false;
        }

        public bool AmI(params int[] UserIds)
        {
            return UserIds.Contains(UserId);
        }

        public bool isDeveloper
        {
            get { return Session.Developers.Contains(InitialUserId); }
        }

        public void RefreshYetki()
        {
            DataTable dt = Session.DataManager.ExecuteDataTable("GetCredential", UserId);
            SetYetki(dt);
        }
    }
}